#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os


def find_dir(string, path='..'):
    print('cur dir:%s' % os.path.abspath(path))
    for filename in os.listdir(path):
        deeper_dir = os.path.join(path, filename)
        if os.path.isfile(deeper_dir) and string in filename:
            print('%s with \'t\' in its name' % filename)
        if os.path.isdir(deeper_dir):
            find_dir(string, deeper_dir)

def detect_walk(dir_path):
    for root, dirs, files in os.walk(dir_path):
        for filename in files:
            print("file:%s\n" % filename)
        for dirname in dirs:
            print("dir:%s\n" % dirname)

def search(path=".", name="1"):
    for item in os.listdir(path):
        item_path = os.path.join(path, item)
        if os.path.isdir(item_path):
            search(item_path, name)
        elif os.path.isfile(item_path):
            if name in item:
                print(item_path)

def getFilePath(filename):
    work_dir = os.path.dirname(os.path.abspath(__file__))

    CONF_FILE = os.path.join(work_dir, filename)
    # print(CONF_FILE)
    if os.path.isfile(CONF_FILE):
        return CONF_FILE
    else:
        work_dir = os.path.dirname(work_dir)
        CONF_FILE =os.path.join(work_dir, filename)
        if os.path.isfile(CONF_FILE):
            return CONF_FILE


if __name__ == '__main__':
    # find_dir('sfq')
    print(getFilePath('datas.conf'))
